/**
 * Created by thinkjoy on 2017/7/25.
 */
    // 基于准备好的dom，初始化echarts实例
$(function () {
    //后台用户男女比例
    var myChart = echarts.init(document.getElementById('sexdata'));
    $.ajax({
        url:'/admin/adminlist/sexdata',
        type:'post',
        dataType:'json',
        success:function (result) {
            var responseObj=eval('('+'result'+')');
            myChart.setOption({
                title: {
                    text: '后台用户男女比例'
                },
                tooltip: {
                    formatter: function (params) {
                        return params.marker + params.name + ': ' + params.value;
                    }
                },
                textStyle: {
                    fontWeight:'lighter',
                    fontSize:16
                },
                series : [
                    {
                        name: '后台用户男女比例',
                        type: 'pie',
                        radius: '60%',
                        roseType:'angle',
                        data:[
                            {
                                value:responseObj[1].count,
                                name:responseObj[1].sex,
                                itemStyle: {
                                    normal: {
                                        color: '#50d6b0'
                                    }
                                }
                            },
                            {
                                value:responseObj[0].count,
                                name:responseObj[0].sex,
                                itemStyle: {
                                    normal: {
                                        color: '#4bbce7'
                                    }
                                }
                            }
                        ],
                        labelLine: {
                            normal: {
                                lineStyle: {
                                    color: '#83979c'
                                }
                            }
                        }
                    }
                ]
            });
        }
    });

    //当前用户的历史登录情况
    var userLogChart = echarts.init(document.getElementById('userdata'));
    $.ajax({
        url:'/admin/adminlist/usercountdata',
        type:'post',
        dataType:'json',
        success:function (result) {
            var userresult=eval('('+'result'+')');
            userLogChart.setOption({
                title: {
                    text: '当前用户最近7天登录次数'
                },
                tooltip: {},
                itemStyle: {
                    normal: {
                        color:'#50d6b0'
                    }
                },
                xAxis: {
                    data:userresult.key
                },
                yAxis: {},
                series: [{
                    name: '次数',
                    type: 'bar',
                    data: userresult.value
                }]
            });
        }
    });

});
